﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using VFDDriver.Properties;
using System.Net;

namespace VFDDriver.XBMC
{
    public class UDPListener : Task
    {
        protected override int Main()
        {
            UdpClient listener = new UdpClient(Settings.Default.XBMC_UDPPort);
            IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, Settings.Default.XBMC_UDPPort);

            while (!ShouldStop)
            {

                byte[] bytes = listener.Receive(ref groupEP);
                OnMessageReceived(Encoding.ASCII.GetString(bytes, 0, bytes.Length));


            }
            listener.Close();
            return 0;
        }

        private void OnMessageReceived(string p)
        {
            //Fire thread safe Event.
        }
    }
}
